<?php echo form_open(uri_string(), 'class="crud" id="service-form"'); ?>
<?php echo form_hidden('escort_id', $escort->getId()) ?>
<?php 
	$weekdayArray = getScheduleInWeekData_ioc();
	$weekdaySelected = $escort->getWeekdaysArray($user->getId());
	$workingPlacesArray = explode(',', $escort->getWorkingPlaceIds());
	$travelsArray = explode(',', $escort->getTravelIds());
	$servesArray = explode(',', $escort->getServesToIds());
	$servicesArray = explode(',', $escort->getServiceIds());
?>

<fieldset>
	<ul id="personal-content" class="ui-sortable form_inputs">
		<li class="five-column-wrapper" id="header">
			<div class="input type-text five-column">
				<div class="five-column-first">
					&nbsp;
				</div>
				<div class="five-column-second">
				&nbsp;
				</div>
				<div class="five-column-third">
				&nbsp;
				</div>
				<div class="five-column-fourth">
				<?php echo lang('escort_be_escort_public_label')?>
				</div>
				<div class="five-column-fifth">
				<?php echo lang('escort_be_escort_locked_label')?>
				</div>
			</div>
		</li>
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_schedule_label')?></label>
			<div class="select-box" style="margin-right:10px;">
		<?php
			$i = 0; 
			foreach($weekdayArray as $key=>$value): ?>
			<?php 
			$i++;
				$checked = in_array($key,$weekdaySelected) ? 'checked="checked"':'';
				$SCHEDULE = $escort->getSchedule($user->getId(), $key);
				$from = $SCHEDULE ? $SCHEDULE->from : ''; 
				$to = $SCHEDULE ? $SCHEDULE->to : '';
			?>
			<div class="input type-text service-five-column">
				<div class="five-column-first">
					<div class="checkbox-wrapper">
					<input type='checkbox' name='services_weekdays[<?php echo $i?>]' value='<?php echo $key;?>' class="custom" <?php echo $checked;?> />
					<label><?php echo $value;?></label>
					</div>
				</div>
				<div class="five-column-second">	
					<label style="margin-right:5px;float:left;"><?php echo language_translate('services_from');?></label> <?php echo form_dropdown("services_time_from_$key", getHourAndMinuteOptionData_ioc(), array($from) , "id=\"services_time_from_$key\" class=\"custom\" " );?>
				</div> 
				<div class="five-column-third">
					<label style="margin-right:5px;float:left;"><?php echo language_translate('services_to');?></label> <?php echo form_dropdown("services_time_to_$key", getHourAndMinuteOptionData_ioc(), array($to) , "id=\"services_time_to_$key\" class=\"custom\" " );?>
				</div>
				<div class="five-column-fourth">
				<?php if($i==1){ ?>
				<?php echo form_checkbox('public_schedule', 1, $escort->getPublicSchedule(), 'class="escort-checkbox"')?>
				<?php }else{?>
					&nbsp;
				<?php }?>
				</div>
				<div class="five-column-fifth">
				<?php if($i==1){ ?>
				<?php echo form_checkbox('locked_schedule',1,$lockedEscort->getLockedSchedule(), 'class="escort-checkbox"')?>
				<?php }else{?>
					&nbsp;
				<?php }?>
				</div>
			</div>
		<?php endforeach;?>
			</div>
		</li>		
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_calendar_label')?></label>
			<div class="input type-text five-column">
				<div class="five-column-first">
				<?php echo dayMonthYearSelectBox(0, 'servcies_day', 'services_month', 'sevices_year', array('y'), 'class="custom"' ); ?>
				</div>
				<div class="five-column-second">
				<?php echo dayMonthYearSelectBox(0, 'servcies_day', 'services_month', 'sevices_year', array('m_n'), 'class="custom"' );?>
				</div>
				<div class="five-column-third">
					<div id="multi-checkbox-sl-days">
					<?php 
							$WORKING_OBJ = $escort->getWorkingCalendar($user->getId(), 2010, 1);
							$dateArray = $WORKING_OBJ ? explode(',',$WORKING_OBJ->dates) : array() ;
						?>
						<?php echo form_multi_checkbox($name_array = "days_in_month", $value_key_array= daysInMonthDataArray( 1, 2010 ), $value_checked=$dateArray, $divStyle='', $inputStyle ='', true);?>
					</div>
				</div>
				<div class="five-column-fourth">
				<?php echo form_checkbox('public_working_calendar', 1, $escort->getPublicWorkingCalendar(), 'class="escort-checkbox"')?>
				</div>
				<div class="five-column-fifth">
				<?php echo form_checkbox('locked_working_calendar',1,$lockedEscort->getLockedWorkingCalendar(), 'class="escort-checkbox"')?>
				</div>
			</div>
		</li>
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_where_i_work_label')?></label>
			<div class="input type-text five-column">
				<div class="five-column-first">
				<?php 
					echo form_multi_checkbox($name_array = "services_working_places", $value_key_array= getWorkingPlaceData_ioc(), $value_checked=$workingPlacesArray, $divStyle='', $inputStyle ='');
				?>
				</div>
				<div class="five-column-second">
					&nbsp;
				</div>
				<div class="five-column-third">
				&nbsp;
				</div>
				<div class="five-column-fourth">
				<?php echo form_checkbox('public_working_places', 1, $escort->getPublicWorkingPlaces(), 'class="escort-checkbox"')?>
				</div>
				<div class="five-column-fifth">
				<?php echo form_checkbox('locked_working_places',1,$lockedEscort->getLockedWorkingPlaces(), 'class="escort-checkbox"')?>
				</div>
			</div>
		</li>
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_travel_label')?></label>
			<div class="input type-text five-column">
				<div class="five-column-first">
				<?php 
					echo form_multi_checkbox($name_array = "services_travels", $value_key_array= getTravelPlaceData_ioc(), $value_checked=$travelsArray, $divStyle='', $inputStyle ='');
				?>
				</div>
				<div class="five-column-second">
					&nbsp;
				</div>
				<div class="five-column-third">
				&nbsp;
				</div>
				<div class="five-column-fourth">
				<?php echo form_checkbox('public_travel', 1, $escort->getPublicTravel(), 'class="escort-checkbox"')?>
				</div>
				<div class="five-column-fifth">
				<?php echo form_checkbox('locked_travel',1,$lockedEscort->getLockedTravel(), 'class="escort-checkbox"')?>
				</div>
			</div>
		</li>
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_serves_to_label')?></label>
			<div class="input type-text five-column">
				<div class="five-column-first">
				<?php 
					echo form_multi_checkbox($name_array = "services_serves", $value_key_array= getServesToData_ioc(), $value_checked=$servesArray, $divStyle='', $inputStyle ='');
				?>
				</div>
				<div class="five-column-second">
					&nbsp;
				</div>
				<div class="five-column-third">
				&nbsp;
				</div>
				<div class="five-column-fourth">
				<?php echo form_checkbox('public_serves', 1, $escort->getPublicServesTo(), 'class="escort-checkbox"')?>
				</div>
				<div class="five-column-fifth">
				<?php echo form_checkbox('locked_serves',1,$lockedEscort->getLockedServe_to(), 'class="escort-checkbox"')?>
				</div>
			</div>
		</li>
		<li class="five-column-wrapper" id="personal_visit">
			<label for="site_name"><?php echo lang('escort_be_escort_service_services_label')?></label>
			<div class="input type-text five-column">
				<div class="five-column-first">
				<div class="select-box">
				<?php $i=0;$m=ceil(count(getServicesData_ioc())/2); foreach(getServicesData_ioc() as $key => $value): $i++;?>	
				<?php $checked = in_array($key, $servicesArray) ? 'checked="checked"':'';?>
					<div class="checkbox-wrapper">
						<input type="checkbox" <?php echo $checked;?> value="<?php echo $key?>" name="services_services[<?php echo $key?>]" class="custom" /> <label><?php echo $value;?></label>
					</div>
				<?php if($i%$m == 0):?>
					</div>
					<div class="select-box">
				<?php endif;?>	
			<?php endforeach;?>
					</div>
				</div>
				<div class="five-column-second">
				&nbsp;
				</div>
				<div class="five-column-third">
				&nbsp;
				</div>
				<div class="five-column-fourth">
				<?php echo form_checkbox('public_services', 1, $escort->getPublicServices(), 'class="escort-checkbox"')?>
				</div>
				<div class="five-column-fifth">
				<?php echo form_checkbox('locked_services',1,$lockedEscort->getLockedServices(), 'class="escort-checkbox"')?>
				</div>
			</div>
		</li>
	</ul>
	<?php echo form_button(array('id'=>'save-appearance', 'onClick'=>'saveService()','name'=>'add', 'class'=>'btn blue', 'value'=>lang('escort_be_escort_service_save_label'), 'content'=>lang('escort_be_escort_service_save_label')))?>
</fieldset>
<?php echo form_close()?>
<script type="text/javascript">
jQuery(document).ready(function() { 
	var options = { 
		beforeSubmit:  validateB4SubmitServices,  
		success:       processAfterRespondingServices   
	};	
	//jQuery('#submit_services').ajaxForm(options); 
	jQuery('#services_month, #sevices_year').live('change',function(){
		loadAsyncDaysInMonth();
	});
	jQuery('input[name=days_in_month\\[\\]]').live('change',function(){
		saveCalendarsWorking();
	});
});	
function loadAsyncDaysInMonth(){
	escort_id = jQuery("form#service-form input[name='escort_id']").val();
	$year = jQuery('#sevices_year').val();
	$month = jQuery('#services_month').val();
	jQuery('#loading-loading-image-days-in-month').show();
	jQuery('#multi-checkbox-sl-days').html('');
	jQuery.post('./admin/be_escort/service/loadAsyncDaysInMonth',{escort_id: escort_id,year:$year,month:$month},function(res){
		jQuery('#loading-loading-image-days-in-month').hide();
		jQuery('#multi-checkbox-sl-days').html(res);
		//jQuery('#multi-checkbox-sl-days input:checkbox:not([onoff]).custom').checkbox({cls:'jquery-safari-checkbox'});
		//jQuery('#multi-checkbox-sl-days input[onoff]:checkbox.custom').checkbox();
	});
}
function saveCalendarsWorking(){
	$year = jQuery('#sevices_year').val();
	$month = jQuery('#services_month').val();
	$datesArray = getMultiCheckbox('days_in_month');
	$datesString = $datesArray ? $datesArray.join(','):'';
	jQuery.post(BASE_URI+'escorts/saveCalendarWorking_async',{year:$year, month:$month, date:$datesString},function(res){
		if(res != 'ok')
			debug(res);
	});
}
function validateB4SubmitServices(formData, jqForm, options){
	jQuery('#services_loader_image').show();
	return true;
}

function processAfterRespondingServices(responseText, statusText, xhr, $form) {
	jQuery('#services_loader_image').hide();	
	if(responseText == 'ok'){
		queryurl(BASE_URI+'escorts/profile/services');
		reload();
	}else{
		debug(responseText);
	}
}
</script>	